package com.yf1706.service;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yf1706.bean.QuestionBank;
import com.yf1706.dao.jpa.questionBankJDAO;
import com.yf1706.dao.mybatis.IQuestionBankMDAO;

@Service
public class questionBankService {
	
	@Autowired
	private questionBankJDAO qbjdao;
	
	@Autowired
	private IQuestionBankMDAO qbmdao;
	/*新增一个题库*/
	public void saveQb(QuestionBank qb) {
		qbjdao.save(qb);
		
	}
	/*查询所有题库*/
	public List<QuestionBank> queryAllQuestionBank(){
		return qbmdao.queryAllQuestionBank();
	}
	
	
	/*public QuestionBank findByQbName(String qbName) {
		return qbjdao.findByQbName(qbName);
	}*/
	
	/*通过id查找题库*/
	public QuestionBank findByQbId(int qbId) {
		return qbjdao.findByQbId(qbId);
	}
	
	//当添加一个单选题时题库单选题数目加一
	public void changeSingleChoiceNum(HttpSession request) {
		
		int qbId=(int)request.getAttribute("qbid");
		QuestionBank q=qbjdao.findByQbId(qbId);
		q.setSingleChoiceNum(q.getSingleChoiceNum()+1);
		qbjdao.save(q);
	}
	//当添加一个单选题时题库多选题数目加一
		public void changeMultiselect(HttpSession request) {
			
			int qbId=(int)request.getAttribute("qbid");
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setMultiselectNum(q.getMultiselectNum()+1);
			qbjdao.save(q);
		}
		//当添加一个单选题时题库判断题数目加一
		public void changeJudgeNum(HttpSession request) {
			
			int qbId=(int)request.getAttribute("qbid");
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setJudgeNum(q.getJudgeNum()+1);
			qbjdao.save(q);
		}
		//当添加一个单选题时题库填空数目加一
				public void changeFillingNum(HttpSession request) {
					
					int qbId=(int)request.getAttribute("qbid");
					QuestionBank q=qbjdao.findByQbId(qbId);
					q.setFillNum(q.getFillNum()+1);
					qbjdao.save(q);
				}
				//当添加一个单选题时题库综合题数目加一
				public void changeComprehensiveNum(HttpSession request) {
					
					int qbId=(int)request.getAttribute("qbid");
					QuestionBank q=qbjdao.findByQbId(qbId);
					q.setSyntheticalNum(q.getSyntheticalNum()+1);
					qbjdao.save(q);
				}
		//模糊查询题库
		public List<QuestionBank> queryQuestionBankSearch(String qbName,int depId) {
			return qbmdao.queryQuestionBankSearch(qbName, depId);
		}
		//当删除题目时题库对应类型的题目数目减少
		public void updateQuestionSingleChoice(HttpSession request1,int num) {
			int qbId=(int)request1.getAttribute("qbid");
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setSingleChoiceNum(q.getSingleChoiceNum()-num);
			qbjdao.save(q);
		}
		public void updateQuestionMultiSelect(HttpSession request1, int size) {
			int qbId=(int)request1.getAttribute("qbid");
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setMultiselectNum(q.getMultiselectNum()-size);
			qbjdao.save(q);
			
		}
		public void updateQuestionJudge(HttpSession request1, int size) {
			int qbId=(int)request1.getAttribute("qbid");
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setJudgeNum(q.getJudgeNum()-size);
			qbjdao.save(q);
			
		}
		public void updateQuestionFilling(HttpSession request1, int size) {
			int qbId=(int)request1.getAttribute("qbid");
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setFillNum(q.getFillNum()-size);
			qbjdao.save(q);
		}
		public void updateQuestionComprehensive(HttpSession request1, int size) {
			int qbId=(int)request1.getAttribute("qbid");
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setSyntheticalNum(q.getSyntheticalNum()-size);
			qbjdao.save(q);
			
		}
		
		
		//在单选表界面删除时减少对应题库中个数
		public void deleteSingleChoiceByQbId(int qbId) {
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setSingleChoiceNum(q.getSingleChoiceNum()-1);
			qbjdao.save(q);
		}
		public void ChangeSingleChoiceNum(int qbId) {
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setSingleChoiceNum(q.getSingleChoiceNum()+1);
			qbjdao.save(q);
			
		}
		public void deleteMultiselectByQbId(int qbId) {
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setMultiselectNum(q.getMultiselectNum()-1);
			qbjdao.save(q);
			
		}
		public void ChangeMultiSelectNum(int qbId) {
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setMultiselectNum(q.getMultiselectNum()+1);
			qbjdao.save(q);
			
		}
		public void deleteJudgeByQbId(int qbId) {
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setJudgeNum(q.getJudgeNum()-1);
			qbjdao.save(q);
			
		}
		public void ChangeJudgeNum(int qbId) {
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setJudgeNum(q.getJudgeNum()+1);
			qbjdao.save(q);
		}
		public void deleteGapFillingByQbId(int qbId) {
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setFillNum(q.getFillNum()-1);
			qbjdao.save(q);
		}
		public void ChangeFillingNum(int qbId) {
			
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setFillNum(q.getFillNum()+1);
			qbjdao.save(q);
		}
		public void deleteComprehensiveByQbId(int qbId) {
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setSyntheticalNum(q.getSyntheticalNum()-1);
			qbjdao.save(q);
			
		}
		public void ChangeComprehensiveNum(int qbId) {
			QuestionBank q=qbjdao.findByQbId(qbId);
			q.setSyntheticalNum(q.getSyntheticalNum()+1);
			qbjdao.save(q);
			
		}
}
